﻿using System;
using Model;
using Service;

using Resources;



public partial class ProblemAdd : System.Web.UI.Page
{
    private ReferenceDataServiceProblem _DataServiceProblem = new ReferenceDataServiceProblem();

    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void bntValidate_Click(object sender, EventArgs e)
    {
        //GroupProblem groupProblem = new GroupProblem();
        //groupProblem.TypeEquipmentId = (Int32.Parse(drlTypeequipment.SelectedValue));
        //groupProblem.GroupProblemLabel = txtProblemgroup.Text;
        //_DataServiceProblem.SaveGroupProblem(groupProblem);
        //ClearControlAdd();


        if (!new Utility().TestPermissions(Resource.PermissionAddProblem))
        {
            lblPermission.Text = Resource.Permission;
            return;
        }
        AddGroupProblem();
    }
    private void AddGroupProblem()
    {
        GroupProblem groupProblem = new GroupProblem();
        if (drlTypeequipment.SelectedIndex!=0)
        {
            groupProblem.TypeEquipmentId = (Int32.Parse(drlTypeequipment.SelectedValue));
            lblRequireTypeequipment.Text = "";
        }
        else {
            lblRequireTypeequipment.Text = Resource.ValueRequire;
            lblRequireGroupProblem.Text = "";
            lblMessageValidate.Text = ""; 
            return;
        }
        if(!string.IsNullOrEmpty(txtProblemgroup.Text))
        {
            _DataServiceProblem.SaveGroupProblem(groupProblem);
            lblMessageValidate.Text = Resource.MessageValidate; 
            ClearControlAdd();  
        }
        else
        {
            lblRequireGroupProblem.Text = Resource.ValueRequire;
            lblRequireTypeequipment.Text = ""; 
            return;   
        }
    }
    public void ClearControlAdd()
    {
        drlTypeequipment.SelectedIndex = -1;
        txtProblemgroup.Text = "";
        lblRequireGroupProblem.Text = ""; 
    }
    public void SaveGroupProblem()
    {
        //int tyoeEquipmentId = drlTypeequipment.SelectedItem.ToString() ;   

    }
  
    protected void bntCancel_Click(object sender, EventArgs e)
    {
        ClearControlAdd();
    }
    public int GetProblemId()
    {
        return !String.IsNullOrEmpty(Request.QueryString["problemId"]) ? Int32.Parse(Request.QueryString["problemId"]) : 0;
    }
}
